package com.code.module.process;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.code.base.acc.pojo.AccSp;
import com.code.base.acc.service.AccPsnService;
import com.code.base.acc.service.AccSpService;
import com.code.base.busi.pojo.BusiDepReq;
import com.code.base.busi.service.BusiDepListService;
import com.code.base.busi.service.BusiDepReqService;
import com.code.base.dic.pojo.DicDepMode;
import com.code.base.dic.service.DicDepModeService;
import com.code.util.DateUtil;

/**
 * @author Administrator
 */
public class StepFunc {
	
	@Resource
	private AccPsnService accPsnService;
	
	@Resource
	private AccSpService accSpService;
	
	@Resource
	private BusiDepReqService busiDepReqService;
	
	@Resource
	private BusiDepListService busiDepListService;
	
	@Resource
	private DicDepModeService dicDepModeService;
	
	private static StepFunc instance;
	
	public static StepFunc getInstance() {
		if (null == instance) {
			instance = new StepFunc();
		}
		return instance;
	}
	
	private StepFunc() {
	}
	
	public int getDepInfo() {
		
		return 0;
	}
	
	
	
	/**
	 * 903
	 * 日间交易服务验证
	 * @param busiDepReq		缴存申请
	 * @return					专户信息
	 */
	public AccSp serviceCheck(BusiDepReq busiDepReq) {
		//a_trdMode	
		//r_spAccInfo	->	ACC_SP
		AccSp accSp = new AccSp();
		accSp.setBankCode(busiDepReq.getBankCode());
		accSp.setAccType(busiDepReq.getAccType());
		List<AccSp> accSpes = accSpService.getDataByCondition(accSp);
		if (accSpes.size() > 0) {
			return accSpes.get(0);
		} else {
			return null;
		}
	}
	
	
	public void tallyCheck() {
		
	}
	

	
	/**
	 * 101
	 * 交存验证
	 * @param busiDepReq			缴存申请
	 * @param accSp					专户信息
	 * @return
	 */
	public boolean depCheck(BusiDepReq busiDepReq, AccSp accSp) {
		if (busiDepReq.getAccType().equals("0")) {
			return false;
			
		} else if (busiDepReq.getAccType().equals("1")) {
			return false;
			
			
		} else if (busiDepReq.getAccType().equals("3")) {
			/**
			 * 判断交存通知书是否已过有效期
			 */
			if (DateUtil.parse(busiDepReq.getValidDate()).getTime() > new Date().getTime()) {
				return false;
			}
			
			/**
			 * 查询虚拟专户信息表,取得其专户账号（取上次查询结果）
			 */
//			if (null == accSp) {
//				accSp = new AccSp();
//				accSp.setBankCode(busiDepReq.getBankCode());
//				accSp.setAccType(busiDepReq.getAccType());
//				List<AccSp> accSpes = accSpService.getDataByCondition(accSp);
//				if (accSpes.size() > 0) {
//					accSp = accSpes.get(0);
//				} else {
//					return false;
//				}
//			}
			
			/**
			 * 更新交存申请表（step = 2）
			 */
			busiDepReq.setStep("2");
			busiDepReq.setCertDate(DateUtil.format());
			busiDepReq.setBankDate(DateUtil.format());
			busiDepReq.setSysDate(DateUtil.format());
			busiDepReq.setChequeNo(accSp.getSpAccNo());
		}
		
		return true;
	}
	
	/**
	 * 191
	 * 交存预处理
	 * @param transCode				交易代码
	 * @param bankCode				承办行代码
	 * @param reqNo						缴存申请编号
	 * @param validateDate			验证日期
	 * @param validateNet				验证网点
	 * @param validateOperater		验证人员
	 * @param trdFrom					发起方
	 * @param hisFlag						历史数据标志
	 * @return									缴存申请
	 */
	public BusiDepReq depPreDeal(String transCode, String bankCode, String reqNo, String validateDate, String validateNet, String validateOperater, String trdFrom, String hisFlag) {
		BusiDepReq busiDepReq = new BusiDepReq();
		busiDepReq.setReqNo(reqNo);
		busiDepReq.setBankCode(bankCode);
		busiDepReq.setHisFlag(hisFlag);
		busiDepReq.setCertDate(validateDate);
		busiDepReq.setReqOper(validateOperater);
		List<BusiDepReq> busiDepReqes = busiDepReqService.getDataByCondition(busiDepReq);
		
		if (busiDepReqes.size() > 0) {
			return busiDepReqes.get(0);
		} else {
			return null;
		}
	}
	
	
	
}
